#include <ctype.h>
#include<iostream>
#include<string.h>
#include<ctype.h>
using namespace std;
//方法一 直接模拟
class Solution {
public:
    bool strongPasswordCheckerII(string password) {
        if (password.size() < 8)return false;
        int lower = 0, upper = 0, digit = 0, star = 0, special = 0;
        for (int i = 0; i < password.size(); i++)
        {
            if (i > 0)
            {
                char ret = password[i - 1];
                if (ret == password[i])return false;
            }
            if (isdigit(password[i]))digit = 1;
            else if (islower(password[i]))lower = 1;
            else if (isupper(password[i]))upper = 1;
            else special = 1;

        }
        if (lower && upper && digit && special)
            return true;
        else return false;
    }
};

//方法二模拟价位运算
class Solution {
public:
    bool strongPasswordCheckerII(string password) {
        if(password.size()<8)return -1;
        int i=0,mask=0;
        while(i<password.size())
        {
            if(i&&password[i]==password[i-1])return false;
            if(isdigit(password[i]))
                mask|=1;
            else if(islower(password[i]))
                mask|=2;
            else if(isupper(password[i]))
                mask|=4;
            else
                mask|=8;
            i++;
        }
        return mask==15;
    }

};
// test
int main()
{
    Solution s1;
    cout << s1.strongPasswordCheckerII("IloveLe3tcode!");
    getchar();
}